package com.yanqu.road.server.cmd.activity.springdinner;

import com.yanqu.road.pb.activity.SpringDinnerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.springdinner.SpringDinnerModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_SPRINGDINNER_GAME_INFO, desc = "请求进入合成大西瓜游戏界面")
public class SpringDinnerGameEnterCmd extends AbstractCommand {

    int activityId;
    int type;
    SpringDinnerProto.SpringDinnerIntoRespMsg.Builder respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SpringDinnerProto.SpringDinnerIntoReqMsg reqMsg = SpringDinnerProto.SpringDinnerIntoReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SpringDinnerModule.class).checkCommon(activityId,type);
        if(ret != 0){
            return;
        }
        //是否解锁
        ret = player.getModule(SpringDinnerModule.class).checkUpLock(activityId,type);
        if(ret != 0){
            return;
        }

        respMsg = player.getModule(SpringDinnerModule.class).enterGame(type);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            respMsg = SpringDinnerProto.SpringDinnerIntoRespMsg.newBuilder();
            respMsg.setRet(ret);
        }
        player.sendPacket(Protocol.U_SPRINGDINNER_GAME_INFO, respMsg);
    }
}
